<?php
class RegisterController extends CommonController {
	private $model;

	public function __auto() {
		$this -> model = K('User');
	}

	//注册方法
	public function index() {
		if (IS_POST) {
			//			p($_POST);
			if (!$this -> model -> addData()) {
				$this -> error($this -> model -> error);
			}
			$this -> success('注册成功', U('Login/index'));
		}

		$this -> display();
	}

	//显示验证码
	public function code() {
		$code = new Code();
		$code -> show();
	}
	
	/**
	 * 异步检测用户名是否存在--注册
	 */
	public function check_REG_User(){
	    if(!IS_AJAX) return;
		$username = Q('post.username');
		$data=K('User')->where("username='{$username}'")->find();
		if($data){
			echo json_encode(array('status'=>false,'message'=>'用户名已存在'));
		}else{
			echo json_encode(array('status'=>true,'message'=>'用户名可以注册'));
		}
		exit;
	}
	
	
}
?>